package stackUsage;

import java.util.Stack;

/**
 * @author le
 */
public class DeleteNeighborElement
{
    private final static String str = "abbaca";

    public static void main(String[] args) throws Exception
    {
        char[] chars = str.toCharArray();
        Stack<Character> stack = new Stack<>();
        stack.push(chars[0]);
        for (int i = 1; i < chars.length; i++)
        {
            // 注意有可能栈为空
            if (stack.empty() || !stack.peek().equals(chars[i])){
                stack.push(chars[i]);
            }else
            {
                stack.pop();
            }
        }
        System.out.println(stack.toString());
    }
}
